package meihua.stopcarapp.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.OnClick;
import meihua.mylibrary.base.BaseActivity;
import meihua.stopcarapp.R;
import meihua.stopcarapp.app.UserConfig;
import meihua.stopcarapp.bean.result.MyWalletResult;
import meihua.stopcarapp.model.MyWalletModel;
import meihua.stopcarapp.presenter.MyWalletPresenter;
import meihua.stopcarapp.presenter.contract.MyWalletContract;

public class MyWalletActivity extends BaseActivity<MyWalletPresenter,MyWalletModel> implements MyWalletContract.View {

    @Bind(R.id.toolbar_left)
    ImageView toolbarLeft;
    @Bind(R.id.toolbar_center)
    TextView toolbarCenter;
    @Bind(R.id.toolbar_right)
    ImageView toolbarRight;
    @Bind(R.id.toolbar)
    RelativeLayout toolbar;
    @Bind(R.id.tv_my_money)
    TextView mMoneytxt;
    @Bind(R.id.tv_money_number)
    TextView mNumbertxt;
    @Bind(R.id.btn_detial)
    Button mDetialtxt;
    @Bind(R.id.btn_charge_money)
    Button mChargeMoneybtn;
    @Bind(R.id.tv_car_quan)
    TextView mQuanTxt;
    @Bind(R.id.ll_my_car)
    LinearLayout mMyCarlayout;
    @Bind(R.id.tv_my_yajin)
    TextView mMyYajintxt;
    @Bind(R.id.ll_my_yajin)
    LinearLayout mMyYajinlayout;
    @Bind(R.id.tv_share_money)
    TextView tvShareMoneytxt;
    @Bind(R.id.ll_share_money)
    LinearLayout mShareMoneylayout;
    @Bind(R.id.activity_my_wallet_progressbar)
    ProgressBar progressBar;

    @Override
    public int getLayoutId() {
        return R.layout.activity_my_wallet;
    }

    @Override
    public void initPresenter() {
        mPresenter.setVM(this,mModel);
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        toolbarCenter.setText("我的钱包");
        mPresenter.getMyWalletListRequest(UserConfig.USER_ENTITY.getUser_id());

    }

    /**
     * 入口
     *
     * @param activity
     */
    public static void startAction(Activity activity) {
        Intent intent = new Intent(activity, MyWalletActivity.class);
        activity.startActivity(intent);
    }

    @OnClick({R.id.ll_my_car, R.id.ll_my_yajin, R.id.ll_share_money,R.id.btn_charge_money,R.id.toolbar_left})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.toolbar_left:
                finish();
                break;
            case R.id.ll_my_car:
                StopCarQuanActivity.startAction(this);
                break;
            case R.id.ll_my_yajin:
                break;
            case R.id.ll_share_money://共享收益
                ShareMoneyActivity.startAction(MyWalletActivity.this);
                break;
            case R.id.btn_charge_money:
                ChargeMoneyActivity.startAction(MyWalletActivity.this);
                break;
        }
    }

    @Override
    public void showLoading(String title) {
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void stopLoading() {

        progressBar.setVisibility(View.GONE);
    }

    @Override
    public void showErrorTip(String msg) {
    }

    @Override
    public void returnMyWalletList(MyWalletResult myWallets) {
        mNumbertxt.setText(myWallets.getUser_balance());
        mQuanTxt.setText(myWallets.getCoupons()+"张");
        mMyYajintxt.setText(myWallets.getUser_deposit()+"元");
        tvShareMoneytxt.setText(myWallets.getEarnings_money()+"元");
    }

}
